using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Map : MonoBehaviour
{
    public GameObject PeanutPrefab;
    public GameObject SquirrelPrefab;
    public GameObject MousePrefab;
    public int StartPeanutNum;
    public int StartSquirrelNum;
    public int StartMouseNum;
    public float CreateInterval;

    public Home MouseHome;
    public Home SquirrelHome;

    private Vector2 ScreenSize;
    private float CreateTimer;

    // Start is called before the first frame update
    void Start()
    {
        ScreenSize = Camera.main.ScreenToWorldPoint(new Vector3(1, 1, 0));

        for (int i = 0; i < StartPeanutNum; i++)
        {
            Instantiate(PeanutPrefab, new Vector2(
                            Random.Range(-ScreenSize.x, ScreenSize.x),
                            Random.Range(-ScreenSize.y, ScreenSize.y)
                            ), Quaternion.identity);
        }

        for (int i = 0; i < StartSquirrelNum; i++)
        {
            Instantiate(SquirrelPrefab, SquirrelHome.transform.position, Quaternion.identity);
        }
        CreateMouse(StartMouseNum);
    }

    // Update is called once per frame
    void Update()
    {
        //if (Input.GetMouseButtonDown(0))
        //    Instantiate(MousePrefab, (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition), Quaternion.identity);

        CreateTimer += Time.deltaTime;
        if (CreateTimer >= CreateInterval)
        {
            CreateTimer = 0;
            Instantiate(PeanutPrefab, new Vector2(
                            Random.Range(-ScreenSize.x, ScreenSize.x),
                            Random.Range(-ScreenSize.y, ScreenSize.y)
                            ), Quaternion.identity);
        }
    }

    public void CreateMouse(int num) 
    {
        for (int i = 0; i < num; i++)
        {
            Instantiate(MousePrefab, MouseHome.transform.position, Quaternion.identity);
        }
    }
}
